package com.scott.redis.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 黄后林
 * @version 1.0
 * @note
 * @date 2022-03-26 22:51:12
 */

@RestController
@RequestMapping("redis")
public class RedisController {

    @Autowired
    private RedisTemplate redisTemplate;

    // http://localhost:8090/redis/hello
    @GetMapping("hello")
    public String hello(){

        //往redis中插入1个key
        redisTemplate.opsForValue().set("scott","huanglaoshi");
        String scott = (String)redisTemplate.opsForValue().get("scott");
        return scott;
    }
}
